package com.itcast.myrpc.test;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @program: bio_tcp
 * @description: 写入操作
 * @author: zhanghz001
 * @create: 2021-02-22 11:46
 **/
public class ByteBufTest02 {
    public static void main(String[] args) {
        //构建
        ByteBuf byteBuf = Unpooled.buffer(10, 20);
        //    打印现在的情况
        System.out.println("byteBuf现在的容量: " + byteBuf.capacity());
        System.out.println("byteBuf可读的容量: " + byteBuf.readableBytes());
        System.out.println("byteBuf可写的容量: " + byteBuf.writableBytes());
        
        //写入几个int后再打印情况
        for (int i = 0; i < 5; i++) {
            byteBuf.writeInt(i);
        }
        System.out.println("ok");
        
        System.out.println("byteBuf现在的容量: " + byteBuf.capacity());
        System.out.println("byteBuf可读的容量: " + byteBuf.readableBytes());
        System.out.println("byteBuf可写的容量: " + byteBuf.writableBytes());
        
        //读取出来
        while (byteBuf.isReadable()) {
            System.out.println(byteBuf.readInt());
        }
    }
}
